<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>红包配置</title>
<link rel="stylesheet" href="/dvmini/res/plugins/layui/css/layui.css">
<link rel="stylesheet" href="/dvmini/res/css/basic.css">
<style>
.layui-form-label{
	width:100px;
}
.layui-form-item h4{
line-height:40px;
font-size:14px;
color:333;
}
.redpagebox{
	padding:10px 100px 0 10px;
}
.redpagebox .layui-input-block{
	margin-left:0;
}
.red{
color:red;
margin-right:5px;
}
</style>
<script src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script>
<body class="wrap">
<form class="layui-form" style="margin-top:20px;">

	<div style="width:350px;float:left;">
		<div class="layui-form-item">
			<label for="" class="layui-form-label"><i class="red">*</i>活动开启时间 </label>
			<div class="layui-input-inline">
				<div class="layui-input-inline">
					<!--<input type="text" name="begintime" autocomplete="on" id="stTime" placeholder="- 开始时间 -" class="layui-input" lay-verify="required" onclick="layui.laydate({elem: this,format: 'YYYY-MM-DD hh:mm',istime: true})">-->
					<input type="text" name="beginTime" autocomplete="on" id="stTime" placeholder="- 开始时间 -" class="layui-input" lay-verify="required" onclick="layui.laydate({elem: this,format: 'YYYY-MM-DD hh:mm',istime: true,min:laydate.now(-1)})">
				</div>
			</div>
			
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><i class="red">*</i>活动状态</label>
			<div class="layui-input-inline">
				<select name="status" lay-verify="required" disabled>
					<option value="0">请选择状态 </option>
					<option value="1">未开启 </option>
					<option value="2"> 进行中</option>
					<option value="3"> 已结束</option>
				</select>
				
				
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><i class="red">*</i>发放红包预算 </label>
			<div class="layui-input-inline">
				<input type="number" name="planMny" class="layui-input" lay-verify="required" />
			</div>
		</div>
	</div>
	<div style="width:600px;float:left;">
		<div class="layui-form-item">
			<label class="layui-form-label">红包活动范围 </label>
			<div class="layui-input-inline" >
				<input type="text" name="city" class="layui-input" />
			</div>
		</div>
		
		<div class="layui-form-item">
			<label class="layui-form-label">红包中奖概率 </label>
			<div class="layui-input-inline">
				<input type="number" name="lotteryPercent" class="layui-input" lay-verify="required" />
			</div>
			<div class="layui-input-inline" style="width:20px;padding:9px 0px;">
				%
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><i class="red">*</i>红包随机金额 </label>
			<div class="layui-input-inline" style="width:100px;">
				<input onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" type="number" name="minMny" class="layui-input" lay-verify="required" min="1">
				<!-- <input type="number" name="minMny" class="layui-input" lay-verify="required" min="1"/> -->
				
			</div>
			
			<div class="layui-input-inline" style="width:20px;padding:9px 0px;">
				至
			</div>
			<div class="layui-input-inline" style="width:100px;">
				<input type="number" name="maxMny" class="layui-input" lay-verify="required" min="1"/>
			</div>
			<div class="layui-input-inline" style="width:20px;padding:9px 0px;">
				分
			</div>
				<div class="layui-form-mid layui-word-aux">提示：只能输入正整数</div>
		</div>
	</div>
	
	
	<div class="layui-form-item redpagebox">
		<h4>粉丝输入以下关键字将触发万小二抽奖功能（多个关键字以“|”分隔）</h4>
		
		<div class="layui-input-block">
			<input type="text" name="keyword" class="layui-input"  placeholder="万小二|红包|抽奖"/>
		</div>
	</div>
	<div class="layui-form-item redpagebox">
	<h4>粉丝未中奖时万小二回复内容</h4>
		<div class="layui-input-block">
			<input type="text" name="unLotteryReply" class="layui-input" placeholder="不开心，小主人没有中奖呃"/>
		</div>
	</div>
	<div class="layui-form-item redpagebox">
		<h4>活动结束后新粉丝触发抽奖后万小二回复内容</h4>
		<div class="layui-input-block">
			<input type="text" name="finishReply" class="layui-input" placeholder="本次红包活动已结束，请期待下一次吧。"/>
		</div>
	</div>
	<div class="layui-form-item redpagebox">
		<h4>粉丝中奖后，万小二向粉丝推送的红包链接标题</h4>
		<div class="layui-input-block">
			<input type="text" name="lotteryTitle" class="layui-input" placeholder="恭喜你获得一个微信现金红包"/>
		</div>
	</div>
	<div class="layui-form-item redpagebox" >
		<h4>粉丝中奖后，万小二向粉丝推送的红包链接的副标题</h4>
		<div class="layui-input-block">
			<input type="text" name="lotterySubTitle" class="layui-input"  placeholder="请点击领取，即刻到账"/>
		</div>
	</div>
	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label"></label>
		<a class="layui-btn" lay-submit="" lay-filter="submit">保存</a>
		<button class="layui-btn"  lay-submit lay-filter="status2">立即开启活动</button>
		<button class="layui-btn"  lay-submit lay-filter="status3">立即结束活动</button>
		<button class="layui-btn"  lay-submit lay-filter="nextround">开启下一轮</button>
	</div>
</form>
	


</body>

<script src='/dvmini/res/js/jquery.min.js'></script>
<script src="/dvmini/res/plugins/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/dvmini/res/js/me.js"></script>
<script>

   

		layui.use(['form', 'element', 'laydate', 'layer', 'laypage','layedit'], function() {
			var form = layui.form(),
				element = layui.element(),
				laydate = layui.laydate,
				layer = layui.layer,
				laypage = layui.laypage;
			
			  form.render()
			
			  $.post("/dvmini/activity/getActivitySetting",function(data){
					console.log(data);
					 if(data.code==0){
						 var lop=(data.data.lotteryPercent)*100;
						 
						$("input[name=beginTime]").val(toTime_G(data.data.beginTime));
						$("select[name=status]").val(data.data.status);
						$("input[name=planMny]").val(data.data.planMny);
						$("input[name=city]").val(data.data.city);
						$("input[name=lotteryPercent]").val(lop);
						$("input[name=minMny]").val(data.data.minMny);
						$("input[name=maxMny]").val(data.data.maxMny);
						$("input[name=keyword]").val(data.data.keyword);
						$("input[name=unLotteryReply]").val(data.data.unLotteryReply);
						$("input[name=finishReply]").val(data.data.finishReply);
						$("input[name=lotteryTitle]").val(data.data.lotteryTitle);
						$("input[name=lotterySubTitle]").val(data.data.lotterySubTitle);
						form.render();
					} else{
						top.layer.msg(data.msg);
					}
				})   
			  
		

		
			form.on('submit(submit)', function(e){
				var lop=e.field.lotteryPercent;
				e.field.lotteryPercent=lop*0.01;
				 console.log(lop);
				//var data_=JSON.stringify(e.field);
				var data_=e.field;
				$.post("/dvmini/activity/editActivitySetting",data_,function(data){
					console.log(data);
					 if(data.code==0){
						top.layer.msg("修改成功");
						 
					} else{
						top.layer.msg(data.msg);
					}
				})   
				 	
				 
			  });
			  //立即开始
			  form.on('submit(status2)', function(e){
				  var status=$("select[name=status]").val();
				  console.log(status)
				  if(status=="1"){
					  $.post("/dvmini/activity/updateActivityStatus",{status:"2"},function(data){
							console.log(data);
							 if(data.code==0){
								top.layer.msg("开启活动成功");
								 
							} else{
								top.layer.msg(data.msg);
							}
						})   
				  }else{
					  top.layer.msg("只有未开启的活动才可以开启");
				  }
					
					 
				  });
			  //立即结束
			  form.on('submit(status3)', function(e){
				  var status=$("select[name=status]").val();
				  if(status=="2"){
					$.post("/dvmini/activity/updateActivityStatus",{status:"3"},function(data){
						console.log(data);
						 if(data.code==0){
							top.layer.msg("设置活动结束成功");
							 
						} else{
							top.layer.msg(data.msg);
						}
					})   
					  }else{
						  top.layer.msg("只有进行中的活动可以结束");
					  }
					 
				  });
			  //设置下一轮
			   form.on('submit(nextround)', function(e){
				 
				   var status=$("select[name=status]").val();
					  if(status=="3"){
					$.post("/dvmini/activity/clearActivity",function(data){
						console.log(data);
						 if(data.code==0){
							top.layer.msg("开启下一轮成功");
							 
						} else{
							top.layer.msg(data.msg);
						}
					})   
					  }else{
						  top.layer.msg("活动结束后才能开启下一轮");
					  } 
					 
				  });
			  

		})
		
		function toTime_G(v) {
		    if (v == null || v == "") {
		      return "";
		    } else {
		      var time = new Date(v)
		      var year = time.getFullYear()
		      var mon = time.getMonth() + 1;
		      var day = time.getDate();
		      var hour = time.getHours();
		      var min = time.getMinutes();
		      if (mon < 10) mon = "0" + mon
		      if (day < 10) day = "0" + day
		      if (hour < 10) hour = "0" + hour
		      if (min < 10) min = "0" + min
		      return year + "-" + mon + "-" + day + " " + hour + ":" + min
		    }
		  }
	</script>

    <!-- 配置文件 -->
    <script type="text/javascript" src="/dvmini/res/UE/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="/dvmini/res/UE/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->


</html>